<template>
  <!-- 全局快捷键组件，不渲染任何内容 -->
</template>

<script setup>
import { onMounted, onBeforeUnmount } from 'vue'
import { useTagsView } from '@/composables/useTagsView'
import { useRoute } from 'vue-router'

const route = useRoute()
const { closeSelectedTag, closeAllTags, closeOthersTags } = useTagsView()

// 键盘事件处理
const handleKeyDown = (e) => {
  // Ctrl+W 或 Command+W：关闭当前标签
  if (e.key === 'w' && (e.ctrlKey || e.metaKey)) {
    e.preventDefault()
    if (route.path !== '/dashboard') {
      closeSelectedTag(route)
    }
  }
  
  // Ctrl+Shift+W 或 Command+Shift+W：关闭所有标签
  if (e.key === 'W' && (e.ctrlKey || e.metaKey) && e.shiftKey) {
    e.preventDefault()
    closeAllTags()
  }
  
  // Ctrl+Alt+W 或 Command+Alt+W：关闭其他标签
  if (e.key === 'w' && (e.ctrlKey || e.metaKey) && e.altKey) {
    e.preventDefault()
    closeOthersTags(route)
  }
}

onMounted(() => {
  document.addEventListener('keydown', handleKeyDown)
})

onBeforeUnmount(() => {
  document.removeEventListener('keydown', handleKeyDown)
})
</script>